home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Atari Compendium
/
The Atari Compendium (Toad Computers) (1994).iso
/
files
/
umich
/
telecomm
/
t100.zoo
/
t100.c
< prev
next >
Wrap
C/C++ Source or Header
|
1991-09-22
|
20KB
|
957 lines
/*
* t100 - simple term emulator. vt52 and ANSI (much of vt100)
*
* by Bill Rosenkranz (rosenkra@convex.com).
*
* based on st52 program by Nick Castellano (entropy@ai.mit.edu) but
* greatly changed so it bears little resemblence. i added the vt100
* support, including font changes. also lifted rs232init from Howard
* Chu's tip and rs232cd (carrier detect) from Steve Yelvington.
*
* this was written with gcc 1.40 (and MiNT 10 libraries).
*
* currently it is hardwired to vt100 (vt100_mode==1 always). i am
* not sure why you'd want vt52 anyway. you can toggle this by adding
* code to set vt100_mode to 0 (the host better know you changed!).
* my reference for the ANSI/vt100 escape codes was an old Falco
* terminal manual. it may not be accurate/modern/complete but does
* seem accurate for all the escapes i find in standard vt100 termcap.
*
* it should be easy to hack in an escape to execute shell commands.
* i just have not done it. that way you could start up a kermit
* or xmodem or whatever. i have not tested this under MiNT or mgr.
*
* restrictions: to (re)set the fonts, i do a line A init ($A000)
* to get the fonthdr pointer and from there get the address of the
* font data. i poke in a new address to my own data, being careful
* to set it back on exit (i hope :-). this means if your big-screen
* monitor can't support this, you are SOL. it also won't run on a
* TT since line A went bye-bye. note that you can always recompile
* with -UUSE_FONTS and it should work fine on any system. you just
* won't have bold and underline.
*
* also, if you define SET_RS232_INIT at compile time, this relies
* on Rsconf returning a value. my understanding is that this does
* not work on TOS 1.0. the safe bet would be to check the TOS
* version. i have not tested this part of the code. currently,
* the rs232 paramaters are hardwired. i would set it from the
* control panel.
*
* major problem: i can't figure out how to tell the host we are an
* 80x25 term without changing /etc/termcap (difficult to do without
* the root passwd). setting TERMCAP did not help, at least with
* GNU emacs and less. maybe there is a termcap for 80x25 but i never
* checked. standard vt100 and vt100n has li set to 24. emacs manual
* sez stuff about this (maybe set TERM to vt100-25?). i have no idea
* about VMS and other non-unix systems with user library routines whose
* names contain "$". why bother? :-)
*/
#ifndef lint
static char *rcsid_t100_c = "$Id: t100.c,v 1.0 1991/09/12 20:32:56 rosenkra Exp $";
#endif
/*
* $Log: t100.c,v $
* Revision 1.0 1991/09/12 20:32:56 rosenkra
* Initial revision
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <osbind.h>
#include <mintbind.h>
#include <signal.h>
#include "t100.h"
#define MINTID "MiNT" /* MiNT's cookie string */
#define MAXWAIT 1000 /* see note in main loop */
#define PROMPT_STRING "\n\rt100> " /* MUST contain a newline */
#define NEWLINE 10 /* common chars */
#define ESC 27
#define RETURN 13
/*
* globals
*/
char iobuf[8192]; /* new iorec for rs232 (first half */
/* is in, second half out) */
_IOREC *recsav; /* ptr to iorec struct */
_IOREC oldirec; /* old input iorec */
_IOREC oldorec; /* old output iorec */
int par = 0; /* none, odd, even - 0, 1, 2 */
int baud = 4; /* see baud table 4=2400 */
int echo = 0; /* 0=off, 1=on */
int flow = 0; /* none, xon/xoff, rts/cts */
int ucr, rsr, tsr, scr; /* for resetting rs232 regs */
char *bauds[] = {"19200","9600","4800","3600","2400","2000",
"1800","1200","600","300","200","150","134",
"110","75","50"}; /* unused */
int vt100_mode = 1; /* 0 means revert to vt52 */
long mintcookie = 0L; /* if MiNT this will be non-NULL */
/*
* vt100 modes, etc...
*/
int bold = 0; /* OFF 1m */
int underline = 0; /* OFF 4m */
int blinking = 0; /* OFF 5m */
int reverse = 0; /* OFF 7m */
int wrap = 1; /* ON (set) */
int video = 0; /* 0=normal (reset) */
int repeat = 1; /* ON (set) */
int curskey = 0; /* OFF (reset) */
int keypad = 0; /* 0=normal (reset) */
int colwidth = 0; /* 0=80 (reset), 1=132 */
int smooth = 0; /* OFF (reset) */
int origmode = 0; /* 0=normal (reset) */
short kbinit, kbrpt; /* saved key repeat stuff */
int outtran[256]; /* char xlation table */
/*------------------------------*/
/* main */
/*------------------------------*/
int main (int argc, char *argv[], char *envp[])
{
short kbret;
int x;
register long key; /* raw Bconin value */
register int gnsrgh = MAXWAIT;
register int c;
#ifdef JUNK
/* this was in st52 code. i don't use it...(it was #ifdef'd already) */
char *terminal;
char *etmp;
char *newenv;
etmp = (char *) envp;
terminal = getenv ("TERM");
#ifdef DEBUG
Cconws ("Terminal type: ");
puts (terminal);
#endif
if (strcmp (terminal, "mgr") == 0)
{
#ifdef DEBUG
puts ("yep");
printf ("value: %d\n",
Pexec (200, "e:\\mint\\mgr\\bin\\vt52.prg",
"e:\\mint\\mgr\\bin\\vt52.prg t100", envp));
#else
Pexec (200, "e:\\mint\\mgr\\bin\\vt52.prg",
"e:\\mint\\mgr\\bin\\vt52.prg t100", envp);
#endif
}
#endif /*JUNK*/
/*
* some initializations: key repeat (save old) and wrap ON
*/
kbret = (short) Kbrate (15, 2);/* repeat ESC [ ? 8 h */
kbinit = (kbret >> 8) & 0x00ff;
kbrpt = kbret & 0x00ff;
Bconout (CON, (int) 27); /* wrap ESC [ ? 7 h */
Bconout (CON, (int) 'v');
/*
* set up output char translation array (normally output==input,
* but you can remap if you want here)
*/
for (x = 0; x < 256; x++)
outtran[x] = x;
#ifdef SWAP_DEL_AND_BS
/*
* this swaps DEL and BS
*/
outtran[127] = 8;
outtran[8] = 127;
#endif
/*
* check for MiNT cookie
*/
mintcookie = getcookie (MINTID);
#ifdef DEBUG
printf ("MiNT cookie %lx detected\n", mintcookie);
#endif
#ifdef USE_FONTS
/*
* set fonts
*/
#ifdef DEBUG
Cconws ("\n\rset fonts...\n\r\n\r");
#endif
if (vt100_mode)
fnt_roman ();
#if 0
/* test fonts */
Cconws ("Roman font (normal)\n\r");
fnt_bold (); Cconws ("BOLD font\n\r");
fnt_uline (); Cconws ("uline font\n\r");
fnt_reverse (); Cconws ("reverse font\n\r");
fnt_roman (); Cconws ("back to Roman\n\r\n\r\n\r");
Cconws ("roman ");
fnt_bold (); Cconws ("bold ");
fnt_uline (); Cconws ("uline ");
fnt_reverse (); Cconws ("reverse ");
fnt_roman (); Cconws ("roman\n\r\n\r");
#endif
#else /*! USE_FONTS*/
vt100_mode = 0;
#endif /*USE_FONTS*/
#if 0
/* test Setcolor */
Setcolor (0,0);
Setcolor (1,0x777);
Cconws ("any key\n\r");
Crawcin ();
Setcolor (0,0x777);
Setcolor (1,0);
#endif
/*
* introductions...
*/
blurb ();
/*
* initialize rs232 (buffers and baud)
*/
Cconws ("\n\rinitialize rs232...\n\r");
rs232init ();
Cconws ("baud set to 2400.\n\r");
/*
* prompt
*/
Cconws (PROMPT_STRING);
/*
* main loop...
*/
for (;;)
{
/*
* if there are characters at the AUX port, and we are
* not going to interrupt, print them. without the
* gnsrgh value, we can't interrupt and send a char.
* MAXWAIT controls how many chars we let in before
* checking the keyboard. 1000 seems reasonable.
*/
if (Bconstat (AUX) && gnsrgh--)
{
/*
* get char
*/
c = (int) Bconin (AUX);
/*
* check for newline. if we are connected do nothing
* special. otherwise print PROMPT_STRING (which
* must have the newline we ignore in it)
*/
if (c == NEWLINE)
{
/*
* if carrier detected...
*/
if (rs232cd ())
{
/*
* ...output the newline...
*/
Bconout (CON, (int) c);
}
else
{
/*
* ...otherwise do our prompt
*/
Cconws (PROMPT_STRING);
}
}
#ifdef EMUL_VT100
else if ((c == ESC) && vt100_mode